package org.com.lcuiot.service;

import org.com.lcuiot.database.dto.Result;
import org.com.lcuiot.database.entity.Area;
import org.com.lcuiot.database.mapper.AreaMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 区域服务
 *
 * @author gaoge
 * @since 2022/11/21 16:23
 */
@Service
public class AreaService {
    private static final Logger logger = LoggerFactory.getLogger(AreaService.class);
    private final AreaMapper areaMapper;

    @Autowired
    public AreaService(AreaMapper areaMapper) {
        this.areaMapper = areaMapper;
    }

    /**
     * 根据设备ID修改设备信息
     *
     * @param organizationId 机构ID
     * @return Result<Object>
     */
    public Result<Object> selectByOrganizationId(Long organizationId) {
        Result<Object> result = Result.build();
        try {
            Area area = new Area();
            area.setOrganizationId(organizationId);
            List<Area> areas = areaMapper.selectList(area);
            result.setData(areas);
        } catch (Exception e) {
            logger.error("根据机构ID查询所有区域信息发生异常:", e);
            result.setCode(500).setMsg("根据机构ID查询所有区域信息发生异常");
        }
        return result;
    }
}
